/*

import java.lang.reflect.Method;

import android.graphics.Canvas;
import android.view.GestureDetector.OnGestureListener;
import android.view.View.OnClickListener;


public interface EventHandlerInterface {
	Object execute(Object param1,Object param2);
}


public interface EventQueueInterface{
	int addListner(int id,EventHandlerInterface handler);
	boolean removeListner(int listnerID);
	void Publish(int id,Object param1,Object param2);
}

public class EventQueue implements EventQueueInterface
{
	private Set<int,EventHandlerInterface> handler_Set;
	boolean addListner(int id,EventHandlerInterface handler){
		//add info to handler_set.
	}
	boolean removeListner(int id,EventHandlerInterface handler){
		//remove info from handler_set.
	}
	Object Publish(int id,Object param1,Object param2){
		//GetHandler from set.
		EventHandlerInterface ref;
		if(ref)
			return ref.execute(param1, param2);
		return null;
	}
}

////////////////////////////////////////////////////////////////////////////////////////////
//SceneTree
////////////////////////////////////////////////////////////////////////////////////////////

public class vcanvas
{
	protected Canvas sys_canvas;
	vcanvas(Canvas c){
		sys_canvas = c;
		m_rotdegree = m_movex = m_movey = 0;
	}
	protected float 	m_rotdegree;
	protected float		m_movex;
	protected float		m_movey;
	protected float		m_drawrect_width;
	protected float		m_drawrect_height;
	
	protected EventQueue m_eventQueue = new EventQueue();
	
	protected DirtyManager m_dm = null;

	public EventQueueInterface GetEventQueue(){
		return m_eventQueue;
	}	
	
	
	//相对于世界坐标系
	protected Rect	GetDrawRect(void){
		return new Rect(m_movex,m_movey,m_movex + m_drawrect_width,m_movey +m_drawrect_height);
	}
	
	protected list<vcanvas>		m_children;
	protected vcanvas  			m_parent;
	
	
	public void Move(x,y){
		m_movex = x;
		m_Movey = y;
	}
	public void Rotate(d){m_rotdegres = d;}
	public void refreshSelf(){
		sys_canvas.postRefresh();
	}
	
	public boolean addChild(vcanvas)
	{
		vcanvas.m_dm = this.m_dm;
		//更新脏区。
		refreshSelf();
	}
	
	public boolean removeChild(vcanvas v)
	{
		//递归，所有子孙的m_dm清空。
		v.m_dm = null;
		refreshSelf();
	}
	
	protected getMovex(){
		float p_movex = 0;
		if(m_parent)
			p_Movex += m_parent.getMovex();
		return m_movex;
	}
	
	boolean	 clipPath(Path path){
	}
	...
	
	void	drawSelfImplement(){
		
	}
	
	void	drawSelf(float px,float py){
		boolean brot = (m_rotdegree != 0);
		p_Movex += px;
		p_Movey += py;
		if(brot)
		{
			sys_canvas.save();
			sys_canvas.rotate(m_rotdegree);
		}
		
		this.drawSelfImplement();
		
		for(o in m_children)
		{
			o.drawSelf(m_movex,m_movey);
		}
		
		p_Movex -= px;
		p_Movey -= py;
		if(brot)
			sys_canvas.restore();
	}
	
	protected void	 drawBitmap(int[] colors, int offset, int stride, float x_orig, float y_orig, int width, int height, boolean hasAlpha, Paint paint)
	{
		boolean brot = (m_rotdegree != 0);
		if(brot)
		{
			sys_canvas.save();
			sys_canvas.rotate(m_rotdegree);
		}
		
		float x = x_orig + getMovex();
		float y = y_orig + getMoveY();
		
		sys_canvas.drawBitmap(...,x,y,....);
		
		
		if(brot)
			sys_canvas.restore();
	}
}

public class Circle : extends vcanvas{
	//不能外部直接设置属性。必须通过接口走，因为接口需要更新藏区。
	protected float x,y,radius;
	void	drawSelfImplement(){
		this.drawCircle(x,y,radius);
	}
	public void SetRadius(float r){
		radius = r;
		m_drawrect_height = r * 2;
		m_drawrect_width = r * 2;
	}
	public void SetCenter(x,y){
		this.x = x;
		this.y = y;
		if(m_eventQueue)
			m_eventQueue.Publish(this.ON_CENTERCHANGE,x,y);
//		refreshThis();
	}
	public static final int ON_CENTERCHANGE = 1;
}

public class DirtyManager{
	protected Region m_dirtyRegion;
	
	//世界坐标系下dirty region.
	public void AddDirtyRect(Rect x)
	{
		m_dirtyRegion.addRect(x);
		m_syscanvas.postInvalidate();
	}
	
	public void clear(){}
	public Region GetRegion(){}
};

public class Stage : extends vcanvas
		implements OnClickListener, OnGestureListener 
{
	public Canvas sys_canvas;
	
	protected DirtyManager m_dm;
	
	//singleton mode.
	public Stage getInstance(){
		//create it.
		this.m_dm = new DirtyManager();
	}
	
	
	protected onMove()
	{
		//递归检查子孙，判定在谁身上。
		//将坐标系转化为命中vcanvas对象的局部坐标系。(可选)
		//publish之。
	}

	//canvas失效，请求重绘:这里注意需要把系统的重绘消息定向如下代码:
	//m_dm.addDirtyRect(0,0,screenWidth,screenHeight);
	public void onInvalidate()
	{
		this.drawSceneTree();
	}
	
	public void drawSceneTree(){
		//如果脏区为空
		if(m_dm)
			sys_canvas.clipRegion(m_dm.GetRegion())
		this.drawSelf(0,0);
		if(m_dm)
		{
			sys_canvas.clipRect(0,0,screenwidth,screenheigth);
			m_dm.clear();
		}
	}
}


public class Background : extends vcanvas
{
	void	drawSelfImplement(){
		this.DrawBitmap(x,y,radius);
	}	
}

static void mian(argc,argv)
{
	
	protected Object OnCircleMoved(Object param1,Object param2)
	{
	}
	
	public class CircleMoved implements EventHandlerInterface {
		Object execute(Object param1,Object param2)
		{
			return null;
		}
	}
	
	CircleMoved handler = new CircleMoved();
	
	Circle c = new Circle(10,100,100);
	c.getEventQueue().addListner(Circle.ON_CENTERCHANGE,handler);
	//
	c.getEventQueue().addListner(Circle.ON_CLICK,handler);
	c.getEventQueue().addListner(Circle.ON_GESTURE,handler);
	
	c.Move(100,100);
	Stage.getInstance().addChild(c);
	Circle c2 = //c...c;
	c.addChild(c2);
	//c2.Move
}


/* 以消息方式来处理了，不需要了。
static void runable()
{
	do{
		//如果脏区不为空，才绘制。
		if(!m_dm.isempty())
			Stage.instance().drawSceneTree();
		//c.Move(random() % 100,random() % 100);
		Sytstem.Sleep(100);
	}while(true);
}
*/
/*}
*/